#pragma once

#include "StringExpression.h"


namespace uml {

StringExpression::StringExpression(const QString& umlType)
    : Expression(umlType) {}

void StringExpression::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Expression::fromJson(json, errorList);
    TemplateableElement::fromJson(json, errorList);
    owningExpression_ = JsonSerializable::create<StringExpression>(json.value("owningExpression"), errorList);

    JsonSerializable::fromJsonArray(subExpressions_, "subExpressions", json, errorList);
}

void StringExpression::toJson(QJsonObject& json) {
    Expression::toJson(json);
    TemplateableElement::toJson(json);
    if (owningExpression_) {
        QJsonObject owningExpression_json;
        owningExpression_->toJson(owningExpression_json);
        json.insert("owningExpression", owningExpression_json);
    }
    JsonSerializable::toJsonArray(subExpressions_, "subExpressions", json);
}

/// <summary>
/// stringValue
    /// The query stringValue() returns the String resulting from concatenating, in
    /// order, all the component String values of all the operands or subExpressions
    /// that are part of the StringExpression.
/// </summary>
    /// <code>
    /// result = (if subExpression->notEmpty()
    /// then subExpression->iterate(se; stringValue: String = '' | stringValue.concat(se.stringValue()))
    /// else operand->iterate(op; stringValue: String = '' | stringValue.concat(op.stringValue()))
    /// endif)
    /// </code>
QString StringExpression::stringValue() const
{
    return "";
}

/// <summary>
/// owningExpression getter
/// The StringExpression of which this StringExpression is a subExpression.
/// </summary>
shared_ptr<StringExpression> StringExpression::owningExpression() const {
    return owningExpression_;
}

/// <summary>
/// owningExpression setter
/// The StringExpression of which this StringExpression is a subExpression.
/// </summary>
void StringExpression::setOwningExpression(shared_ptr<StringExpression> value) {
    owningExpression_ = value;
}

/// <summary>
/// subExpressions getter
/// The StringExpressions that constitute this StringExpression.
/// </summary>
vector<shared_ptr<StringExpression>>& StringExpression::subExpressions() {
    return subExpressions_;
}

} // namespace uml
